#ifndef _GLCALLBATCHER_H_INCLUDED_
#define _GLCALLBATCHER_H_INCLUDED_

// AtlasImage objects send their quads to GLCallBatcher for rendering.
// GLCallBatcher strings the quads together into triangle lists.
// All quads with same alpha, colour, transpancy and texture are rendered together 
// with one call to glDrawElements

#include <GlobalData.h>
//#include "FontAtlas.h"
//#include <Engine2d/Engine2d.h>

class GLCallBatcher
{
private:
	float		*vertexData;	// storage of vertex array
	GLushort	*indices;		// indices of quads
	int 		numQuads;		// current number of quads waiting to be rendered
	int 		sizeCache;		// current amount of quads that can fit in the arrays
	float 		alpha;			// alpha value of current quads
	int 		color;			// colour tint of current quads
	GLuint 		textureID;		// texture of current quads
	bool		transparent;	// are current quads transparent
	int			drawCallCount;	// statistical info
	int 		quadCount;
	bool		smooth;
    uint        increase;       // how many quads to add on reallocation due to too small buffer.

private:
	void Reallocate(int increase);

public:
	GLCallBatcher(uint quads = 128, uint increase = 128);
	~GLCallBatcher();
	void addQuad(GLuint textureID, int color, float alpha, bool transparent, bool smooth, const float* texCoords, const float* vertices);
	void renderCurr();
	void setAttribs(GLuint textureID, int color, float alpha, bool transparent, bool smooth);
	void addQuad(const float* texCoords, const float* vertices);
	void release();
	void resetStats() {
		drawCallCount = 0;
		quadCount = 0;
	}
};

#endif // _GLCALLBATCHER_H_INCLUDED_
